import BaseUtil from '@/BaseUtil';
import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import SelectUtil from '@/SelectUtil';
import EffectCommon from 'code/Core/Common/EffectCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 烈焰之径
 **/
export default class BossSpell_FirePath extends AbilityBase {
    static instance: BossSpell_FirePath;
    buffType: AppBuffType = {
        id: 'buff_BossSpell_FirePath',
        art: this.art,
        name: this.abilityName,
        ubertip: this.ubertip,
        interval: 1,
        onInterval: this.buffInterval.bind(this),
        dur: 5,
        targetAttach: 'overhead',
        targetArt: 'Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeEmbers.mdl',
        isDebuff: true,
    };
    buffInterval(buff: Buff) {
        DamageSystemInstance.applyFireDamage(buff.getParent(), buff.getCaster(), 400, 'fire', true);
    }
    constructor(id: string = 'Myh3') {
        super(id);
        BossSpell_FirePath.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('烈焰之径', source);
        BaseUtil.runLater(1, () => {
            this.effect(source);
            source = null;
        });
    }
    effect(source: unit) {
        let x = GetUnitX(source);
        let y = GetUnitY(source);
        let damagePool: unit[] = [];
        // let ef = AddSpecialEffect('FlameshotAura.mdx', x, y);
        EffectCommon.addEffectAndDeleyRemove('火环\\sem_huo_huan.mdx', x, y, 3);
        BaseUtil.onTimer(0.04, (c) => {
            if (c % 3 == 1) {
                let es = SelectUtil.getEnemyUnitsInRange(source, 50 + c * 7.5, x, y);
                for (let e of es) {
                    if (damagePool.includes(e)) continue;
                    damagePool.push(e);
                    DamageSystemInstance.applyFireDamage(e, source, 4000);
                    BuffUtil.addBuff(e, this.buffType.id, source);
                }
            }
            if (c >= 75) {
                damagePool = null;
            }
            return c < 75;
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
